//-----------------------------------------------------------------------------
// <copyright file="Plugin.cs" company="Justin Wallace Saunders">
//     Copyright (c) Microsoft Public License. All rights reserved.
// </copyright>
// <author name="Justin Wallace Saunders" email="justinsa@live.ca" />
//-----------------------------------------------------------------------------
namespace Community.Tools.Plugins
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// Defines a base class for an IPlugin.
    /// </summary>
    public abstract class Plugin : IPlugin
    {
        /// <summary>
        /// Initializes a new instance of the plugin class.
        /// </summary>
        /// <param name="name">The plugin name</param>
        protected Plugin(string name)
        {
            this.Name = name;
        }

        /// <summary>
        /// An event issued when the plugin desires to be unloaded.
        /// </summary>
        public event EventHandler<PluginUnloadEventArgs> PluginUnloadEvent;

        /// <summary>
        /// Gets the name of the plugin.
        /// </summary>s
        public string Name { get; private set; }

        /// <summary>
        /// Initializes the plugin.
        /// </summary>
        public abstract void Initialize();

        /// <summary>
        /// Executes the plugin.
        /// </summary>
        /// <param name="arguments">A collection of arguments to be processed.</param>
        public abstract void Run(IDictionary<string, object> arguments);

        /// <summary>
        /// Allows the plugin to be disposed of.
        /// </summary>
        public abstract void Uninitialize();

        /// <summary>
        /// Raises a PluginUnloadEvent for this plugin.
        /// </summary>
        protected void CallPluginUnloadEvent()
        {
            if (this.PluginUnloadEvent != null)
            {
                this.PluginUnloadEvent(this, new PluginUnloadEventArgs(this));
            }
        }
    }
}
